﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Domain.Query.Member
{
    public class MemberDetailQuery
    {

        public long? MemberId { get; set; } = null;
        /// <summary>
        /// 不等于
        /// </summary>
        public long? MemberIdNE { get; set; } = null;
        public string MiniProgramOpenId { get; set; } = string.Empty;
        public string WechatOpenId { get; set; } = string.Empty;

        /*************可以进行模糊查询的条件***********************/
        public string Phone { get; set; } = string.Empty;
        public string RealName { get; set; } = string.Empty;
        public string NickName { get; set; } = string.Empty;
        public string Email { get; set; } = string.Empty;

        /// <summary>
        /// 模糊查询
        /// </summary>
        public bool FuzzyQuery { get; set; } = false;

        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <returns></returns>
        public Expression<Func<furion.blog.Domain.MySQL.Member, bool>> Exp()
        {
            var exp = Expressionable.Create<furion.blog.Domain.MySQL.Member>();
            exp.AndIF(MemberId!=null,t=>t.MemberId == MemberId);
            exp.AndIF(MemberIdNE!=null,t=>t.MemberId != MemberIdNE);
            exp.AndIF(!string.IsNullOrWhiteSpace(MiniProgramOpenId),t=>MiniProgramOpenId == MiniProgramOpenId);
            exp.AndIF(!string.IsNullOrWhiteSpace(WechatOpenId), t => t.WechatOpenid == WechatOpenId);

            if (!FuzzyQuery)
            {
                exp.AndIF(!string.IsNullOrWhiteSpace(RealName), t => t.RealName == RealName);
                exp.AndIF(!string.IsNullOrWhiteSpace(Phone), t => t.Phone == Phone);
                exp.AndIF(!string.IsNullOrWhiteSpace(NickName), t => t.NickName == NickName);
                exp.AndIF(!string.IsNullOrWhiteSpace(Email), t => t.Email == Email);
            }
            else
            {
                exp.AndIF(!string.IsNullOrWhiteSpace(RealName), t => t.RealName.Contains(RealName));
                exp.AndIF(!string.IsNullOrWhiteSpace(Phone), t => t.Phone.Contains(Phone));
                exp.AndIF(!string.IsNullOrWhiteSpace(NickName), t => t.NickName.Contains(NickName));
                exp.AndIF(!string.IsNullOrWhiteSpace(Email), t => t.Email.Contains(Email));
            }
            return exp.ToExpression();
        }

    }
}
